package com.dexgdx.game.manager;

import java.util.ArrayList;
import java.util.List;

import com.dexgdx.game.Game;
import com.dexgdx.game.action.IAction;
import com.dexgdx.game.action.pack.ActionPack;

public class ActionManager {
	
	public static void runNextInQueue(){
		if(Game.actionData.actionPackList.size() > 0){
			List<ActionPack> finishedPacks = new ArrayList<ActionPack>();
			int index = 0;
			while ( index < Game.actionData.actionPackList.size()) {
				ActionPack actionPack = Game.actionData.actionPackList.get(index);
				actionPack.runNextStep();
				if(actionPack.isFinished()){
					finishedPacks.add(actionPack);
				}
				index++;
			}
			for (ActionPack actionPack : finishedPacks) {
				Game.actionData.actionPackList.remove(actionPack);
			}
		}
	}
	public static void addToQueueAsSeperateActions(ActionPack actionPack){
		for (IAction action : actionPack.getActionList()) {
			Game.actionData.actionPackList.add(new ActionPack(action));
		}
	}

	public static void addToQueue(ActionPack actionPack){
		Game.actionData.actionPackList.add(actionPack);
	}

	public static void addToQueue(IAction action){
		Game.actionData.actionPackList.add(new ActionPack(action));
	}
	
}
